<template>
        <rx-layout>
            <template v-slot:header>
                <rx-filters :isBpmClient="true"
                            ref="filters"
                            :firstSelected="true"
                            :readType="readType"
                            :readKey="readKey"
                            :treePrefix="treePrefix"
                            :keyname="getTreeCatByList.key" :namelit="getTreeCatByList.name"
                            @loadListByParams="loadListByParams"
                            :placeholder="i18n('enterTask','请输入流程名称')"></rx-filters>
            </template>
            <template v-slot:center>
                <rx-grid ref="rxGrid" :queryParam="queryParam"
                         :url="'/api-bpm/bpm/core/bpmDef/getAllForStart?isMobile=1'">
                    <template v-slot:center="{record}">
                        <view class="rx-center" @click="startForm(record)">
                            <view class="rx-createTime">
                                <my-icon style="color: rgba(66, 133, 244, 1);font-size: 1.2rem"
                                         type="icon-linetime"></my-icon>
                                <view class="rx-createTime-name">{{ record.updateTime }}</view>
                            </view>
                            <view class="rx-top">
                                <view class="rx-icon-le"><view class="rx-icon_liucheng"><my-icon type="icon-Vue3jpaas-icon_liucheng"></my-icon></view></view>
                                <view class="rx-subject">{{ record.name }}</view>
                            </view>
                            <view class="rx-bottom">
                                <view class="rx-bottom-list">
                                    <span class="rx-bottom-span">{{ $ti18('rxForm.key', '编码') }}:</span>
                                    <span class="rx-bottom-name">{{ record.key }}</span>
                                </view>
                                <view class="rx-bottom-list">
                                    <span class="rx-bottom-span">{{ i18n('version', '版本号') }}:</span>
                                    <span class="rx-bottom-name">{{ record.version }}</span>
                                </view>
                            </view>
                        </view>
                    </template>
                </rx-grid>
            </template>
        </rx-layout>
</template>

<script>
import RxGrid from '@/components/RxGrid'
import RxLayout from '@/components/RxLayout'
import RxFilters from '@/components/RxFilters'
import instAndTaskShareApi from "@/api/instAndTaskShareApi";
export default {
    name: "RxMySolutions",
    components: {RxGrid, RxLayout, RxFilters},
    data() {
        return {
            readType: "task",
            readKey: "start.read",
            treePrefix: '',
            isInit: true,
            getTreeCatByList: '',
            queryParam: {},//筛选参数
            treeRootList:[]
        }
    },
    created() {
        this.initParam();
        this.getTreeCatByKey();
    },
    methods: {
        i18n(name, text, key) {
            return this.$ti18(name, text, "bpmLang", key);
        },
        initParam(){
            this.queryParam={
                treeCatType:"allRootApp"
            }
            this.treeRootList = uni.getStorageSync('treeRootList');
            this.queryParam.treeRootList=JSON.stringify(this.getAppList());
        },
        getTreeCatByKey() {
            instAndTaskShareApi.getTreeCatByKey().then(ret => {
                this.getTreeCatByList = ret;
            })
        },
        //筛选
        loadListByParams(params) {
            if(params){
                this.queryParam = params
            }else {
                this.initParam();
            }
        },
        getTwoLetter(word) {
            if (!word) {
                return "";
            } else if (word.length < 2) {
                return word.toUpperCase();
            } else {
                return word.substr(0, 2).toUpperCase();
            }
        },
        startForm(obj) {
            let params = {
                defId: obj.defId,
                defKey: obj.key,
                routerName: 'newDoc',
                action: 'edit'
            }
            let mobileAppId = uni.getStorageSync("mobileAppId");
            let appId = ''
            if (obj.appId) {
                appId = obj.appId ? obj.appId : mobileAppId
            }
            uni.navigateTo({
                url: '/views/modules/bpm/OpenDoc?params=' + JSON.stringify(params) + '&appId=' + appId
            })
        },
        getAppList() {
            let appList = {};
            for (let i = 0; i < this.treeRootList.length; i++) {
                let app = this.treeRootList[i];
                let obj = {
                    appId: app.appId,
                    isAdmin: app.isAdmin
                }
                appList[app.appId] = obj;
            }
            return appList;
        },
    }
}
</script>

<style scoped>
@import "../RxProcessManagement.css";
</style>
